 var table ,form ,laypage ,layer ,element ,laydate ,upload//时间组件
 var zzhtml='';//资质添加弹出框
$(function(){
 layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
     table = layui.table;
     form=layui.form;
     laypage = layui.laypage ;//分页
     layer = layui.layer ;//弹层
     element = layui.element; //元素操作
     laydate = layui.laydate; //时间组件 
     upload = layui.upload;
     //pdf打开文件 
     var w = document.documentElement.clientWidth;
     var h = document.documentElement.clientHeight;
     $('a.mediapdf').media({width: w, height: h});
   //图片上传
     $("body").on("change",".addfile",function (ev) {
     	var thisele=$(this);
     	var imgData;
     	// 构造一个文件渲染对象
         var reader = new FileReader();
         // 得到文件列表数组
         var fileObj = $(this)[0].files[0];
         // 拿到文件数据
         reader.readAsDataURL(fileObj);

         reader.onload = function() {
             // 获取文件信息
             imgData = reader.result;		    
         };
         var formData = new FormData();
         formData.append('myFile', $(this)[0].files[0]); // 固定格式
         var tishi = layer.open({
       	    title: false
             ,closeBtn: 0
             ,shadeClose: false
             ,area: ['130px', '70px']
             ,type: 1
             ,content: '文件上传中...'
         }); 
         $.ajax({
             url:'/scmsCompany/uploadImage.do' ,//后台接收数据地址
             headers: setHeader(),
             data:formData,
             timeout:3600000,
             type: "POST",
             async:true,//请求类型
             dataType: "json",
             cache: false,			//上传文件无需缓存
             processData: false,		//用于对data参数进行序列化处理 这里必须false
             contentType: false,
             success:function(res){
             	if(res.status==200){
             		$(thisele).siblings(".up-img").find('.demo2').append('<tr fileid="">'+
     			   			                '<td><a class="filename" href="/scmsCompany/download.do?filePath='+res.resultData.path+'" download="文件下载">'+ fileObj.name+'</a><input type="hidden" class="enclosure" value="'+res.resultData.path+'"></td>'+
     			   			                '<td>' +      
     			   			                  '<a href="javascript:; return false" class="layui-btn layui-btn-xs layui-btn-danger" imgfileid="" onclick="delecta(this)">删除</a>'+
     			   			                  '<input type="hidden" class="imagemeet"   value='+res.resultData.path +'>'+
     			   			                '</td>'+
     			   			              '</tr>'
     			   			               );
     								 
             		form.render();//需要渲染一下
             	}else if(res.status == 666){
             		TIMEOUT(); 
               }else{
                 	layer.msg(res.resultMsg, {icon: res.icon});                    		
             	}
             	layer.close(tishi);
             }
         })
     });   
 })

})

//资质20项列表
 function itemexaminetype(name,flag,typecount){//typecount 1资质 2三措一案
 	$.ajax({
 		url:'/scmsDict/dictPublic.do',
 		type:'POST',
 		asyn:false,
 		data:{"request":JSON.stringify({"groupId":"item_examine_type"})},
 		timeout: 200000,
 		headers: setHeader(),
 		success:function(data){
 			//获得服务器响应
 			$("#"+name).empty();//清空
 			form.render();  
 			var res = data.resultData;	
 			if(data.status == 200) {
 				if(res.length>0){
 					var html='';
 					$.each(res, function(i,json){
 						//remarks1为显示
 						if(typecount=="1"){
 							if(json["dictId"]!="20"){//资质
 								html+='<div class="layui-colla-item zzmain" remarksstate='+json["remarks"]+' id=' + json["dictId"] + '>'+
										     '<h2 class="layui-colla-title">' + json["dictName"] + '</h2>'+								     
										     '<div class="layui-colla-content zzmesage" >'+
										        '<div class="innerdiv"><i  onclick="addbtn22(this)" class="layui-icon layui-icon-add-circle" style="color:#5cb1dc;font-size:28px;cursor: pointer;"></i></div>'+			
										     '</div>'+
									  '</div>'
 							}
 						}else if(typecount=="2"){//三措一案
 							
 							if(json["dictId"]=="20"){
 								html+='<div class="layui-colla-item zzmain" remarksstate='+json["remarks"]+' id=' + json["dictId"] + '>'+
										     '<h2 class="layui-colla-title">' + json["dictName"] + '</h2>'+								     
										     '<div class="layui-colla-content zzmesage" >'+
										        '<div class="innerdiv"><i  onclick="addbtn22(this)" class="layui-icon layui-icon-add-circle" style="color:#5cb1dc;font-size:28px;cursor: pointer;"></i></div>'+			
										     '</div>'+
									  '</div>'
 							}
 						}else{
 							html+='<div class="layui-colla-item zzmain" remarksstate='+json["remarks"]+' id=' + json["dictId"] + '>'+
									     '<h2 class="layui-colla-title">' + json["dictName"] + '</h2>'+								     
									     '<div class="layui-colla-content zzmesage" >'+
									        '<div class="innerdiv"><i  onclick="addbtn22(this)" class="layui-icon layui-icon-add-circle" style="color:#5cb1dc;font-size:28px;cursor: pointer;"></i></div>'+			
									     '</div>'+
								  '</div>'
 						}												 	                   
 					});
 					$("#"+name).append(html); 					
 					form.render(); 
 					layui.element.init()//折叠面板动态数据处理完毕后
 					//remarks 1为显示0隐藏
 					if(flag){
 						$("#zzlist").find("div[remarksstate='0']").hide()
 					}
 					form.render(); 
 					
 				}
                  
 			}else if(data.status == 666){
 				 TIMEOUT(); 
 		    }else{          	  				    
					layer.msg(data.resultMsg, {icon: data.icon});
			}
 		}		
 	})
 }
////审核流程回显
function backListfun(arry,name){
	if(arry.length>0){
		$.each(arry,function (i, item) {//item即为表格中一行的数据
			if(item.departmentPeople!=""){//有人员
            	if(item.duties==null){
            		item.duties=""
            	}
            	if(item.phone==null){
            		item.phone=""
            	}
        		$("input[name=lctype"+item.type+"][value='0']").attr("checked",item.isMulti == 0 ? true : false);
	  		    $("input[name=lctype"+item.type+"][value='1']").attr("checked",item.isMulti == 1 ? true : false);
            	var maindiv=$("#"+name).find("li[typeid="+item.type+"]").find(".peopleli");
            	var indexnum=$(maindiv).find(".lcitem").length;
            	var shehename='';
            	if(item.departmentState==1||item.departmentState==3){//通过
            		shehename='<span style="color:#5fb878">通过</span>'
            	}else if(item.departmentState==2){
            		shehename='<span style="color:#ff0000">未通过</span>'
            	}else{
            		shehename='<span style="color:#40a2d4">待审核</span>'
            	}
            	if(item.remarks==null){
            		item.remarks=""
            	}
                var idshtml='<div class="lcitem" id='+item.departmentPeople+'>'+//人元id
                                  '<div class="ciosricon">'+shehename+'</div>'+
								  '<div class="" >'+	
								      '<span class="sloat">'+(indexnum+1)*1+'</span><span  class="shpeople">'+item.departmentPeopleName+'</span>'+
								  ' </div>'+
								  '<div class="mgleft bumen">'+
							             '部门：<span id='+item.departmentId+' class="updeparent">'+item.departmentName+'</span>'+
							       '</div>'+
								   '<div class="mgleft zhiwu">'+
								         '职务：<span  class="upuserDuties">'+item.duties+'</span>'+
								   '</div>'+
								   '<div class="mgleft">'+
								           '联系方式：<span>'+item.phone+'</span>'+
								   '</div> '+ 
								   '<div class="mgleft lianxifs">'+
								           '审核备注：<div style="color:#40a2d4">'+item.remarks+'</div>'+
								   '</div> '+
						     '</div>'
				$(maindiv).append(idshtml);	
                form.render();
			}		   
        });
	}
}
//添加项目资质
function addbtn22(e){
	var Parents=$(e).parent(".innerdiv");
    $.ajax({
        url:'/res/page/scmsCompany/zz_data.html',
        type:'get',
        async:false,
        dataType : "html",
        success:function(data){       	        	
        	 var wrappedObj = $("<code></code>").append($(data));
        	 $(Parents).after($(wrappedObj).find("#form_zzdata").html());
        	 $(Parents).next().find(".name_zz").focus();
        	 Timelist();
			 
        	form.render();

        }
    });
    form.render();
}
//资质时间选择
function Timelist(){
    $("body .Timelay").each(function(){
        laydate.render({
          elem: this, //指定元素  表示当前的元素
          type: 'datetime', //date日期  time时间  year年  month月份  
          trigger: 'click'
        });
    })
}
//资质删除按钮
function deleatzzfun(e){
	var item=$(e).parents(".zizhilist");
	$(item).remove();
}
//上传文件
function fileupufn(ele){
	 $(ele).next(".addfile").trigger("click");  //点击按钮对象
}

//图片点击事件
function Viewerfun(th){
	var id=$(th).attr("imgid");
	var viewer = new Viewer(document.getElementById(id), {
		url: 'data-original',
		navbar: false
  });
}
//多图片删除
function delecta(th){
	 $(th).parents("tr").remove();
	 var id=$(th).attr("imgfileid");
 	var requestData={"id":id,"sfImage":$(th).siblings(".imagemeet").val()}
	 $.ajax({
			url:'/scmsCompany/deleteImage.do',
			type:'POST',
			async:false,
			data:formatParam(requestData),
			timeout: 200000,
			headers: setHeader(),
			success:function(res){         //请求成功
	        	   if(res.status == 200)
	        	   {
						layer.msg("文件删除成功", {icon: "6"});	
	    	   		}else if(res.status == 666){
	  					TIMEOUT(); 
	  		        }else{
	  					layer.msg(res.resultMsg, {icon: res.icon});
	  				} 
	        	   return false
	          }		
		})
}